<html>

<head>
<link rel="stylesheet" href="bootstrap.min.css" />
<script src="jquery-1.8.0.min.js"></script> 

<script>

//获得参数的方法

var request = { 

 QueryString : function(val) { 

 var uri = decodeURI(window.location.search); 

 var re = new RegExp("" +val+ "=([^&?]*)", "ig"); 

 return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null); 

 } 

}

</script>

</head>

<body>
<div style="overflow:auto;position: relative;">
   <div id="wwf" class="table table-bordered table-striped">
                     		<table id=table>						
							<thead>
							<tr>							   
							    <th><nobr>订单日期</nobr></th>
							    <th><nobr>配送日期</nobr></th>
							    <th><nobr>调度</nobr></th>
							    <th><nobr>项目</nobr></th>
							    <th><nobr>客户</nobr></th>
							    <th><nobr>配送类型</nobr></th>
							    <th><nobr>货物</nobr></th>
							    <th><nobr>线路备注</nobr></th>
							    <th><nobr>门店</nobr></th>
							    <th><nobr>司机</nobr></th>
							    <th><nobr>车牌</nobr></th>
							    <th><nobr>配送员</nobr></th>
							    <th><nobr>客户合并件数</nobr></th>	
							    <th><nobr>门店备注</nobr></th>							    					 
							</tr>
							</thead>
							<tbody>							
							<!-- <tr>
							    <th></th>						
								<th></th>
								<th></th>						
								<th></th>
								<th></th>						
								<th></th>
								<th></th>						
								<th></th>
								<th></th>						
								<th></th>
								<th></th>						
								<th></th>
								<th></th>																																														
							</tr>		 --> 				
							</tbody>							
						</table>
  </div>
</div>
<div>
<P id="a01">未派车门店:</P>
<P id="a02">未出车司机:</P>
<P id="a03">未使用车辆:</P>

</div>

<script>

///////////////////
//去除重复项函数
//有问题，会导致出现重复项。
///////////////////
/* function unique1(array){
	  var r = [];
	  //console.log(array.length);
	  for(var i = 0, l = array.length; i<l; i++){
		   console.log("dd1"); 
		    console.log(i);
		    console.log("cc1"); 
	    for(var j = i + 1; j < l; j++)
	        {
	    	 console.log("jjii");
	    	 console.log(i);  
      	   console.log(j); 
      	   console.log("jjii"); 
	           if(array[i] == array[j])
	           {	
	        	   console.log("sfs");
	        	   console.log(i); 
	        	   console.log(j); 
	        	   console.log("sfs"); 
	    	       j == ++i;
	    	       console.log("sfs1"); 
	    	       console.log(i); 
	    	       console.log(j);
	    	       console.log("sfs1"); 
	           }
	        }
	     console.log("dd"); 
	    console.log(i);
	    console.log("cc"); 
	    r.push(array[i]);
	  }
	  return r;
} */
//去除重复项
function unique1(arr){
	 let newsArr = [];
	 for (let i = 0; i < arr.length; i++) {
	  if(newsArr.indexOf(arr[i]) === -1){
	   newsArr.push(arr[i]);
	  }
	 }
	 return newsArr;
	}
	
//调用方法获得参数
var rt = request.QueryString("inputStr");
//数据提取
var varAllDb1 = rt.slice(0,rt.search("a001a")).split(',');//车牌 varAllDb1
var varAllDb2 = rt.slice(rt.search("a001a")+5,rt.search("a002a")).split(',');//司机 varAllDb2
var varAllDb3 = rt.slice(rt.search("a002a")+5,rt.search("a003a")).split(',');//门店 varAllDb3
var varAllDb4 = rt.slice(rt.search("a003a")+5,rt.search("a004a")).split(',');//表头
var varAllDb5 = rt.slice(rt.search("a004a")+5,rt.search("a005a")).split(',');//表体派车信息 varAllDb4
var varAllDb6 = rt.slice(rt.search("a005a")+5,rt.length).split(',');//派车日期  出车日期
   var r = [];
for(var i = 0, l = varAllDb5.length; i<l; i=i+4){
   r.push(varAllDb5[i]);	
}
//alert(r);
//console.log(r);
var qcfsj1=unique1(r);
//console.log(qcfsj1);
var xhbiaji = [];
//alert(varAllDb4.length);
for (i = 0; i < varAllDb4.length / 9; i++) {
	
	xhbiaji[i] = new Array(); //将每一个子元素又定义为数组。
	for(var ii = 0, ll = qcfsj1.length; ii<ll; ii=ii+1){
		
		
		   if(varAllDb4[i*9].slice(0,2)==qcfsj1[ii].slice(0,2))
			 {
			   xhbiaji[i].push(qcfsj1[ii]);	
			 }
		   
		}
}
//表头要做乘9处理。
var riqijs=0;//管理派车日期 出车日期。
//console.log(xhbiaji);
//console.log(xhbiaji[0]);
for(var i=0;i<xhbiaji.length;i=i+1)
{
	
	for(var ig=0;ig<xhbiaji[i].length;ig=ig+1)
		{
		
		var hbmd="";//合并门店 按客户
		var hbmdjs=0;
		var tempvar="";//保存客户名称。
		var tempvar1="";//保存合并门店备注
		    for(var iw=0;iw<varAllDb5.length;iw=iw+4)
		    {
		    	
		    	if(xhbiaji[i][ig]==varAllDb5[iw])
		    	{
		    		hbmd=hbmd+varAllDb5[iw+1].slice(2,varAllDb5[iw+1].length)+"/";
		    		
		    	    hbmdjs=hbmdjs+Number(varAllDb5[iw+2].slice(2,varAllDb5[iw+2].length));
		    		
		    		tempvar1=tempvar1+varAllDb5[iw+3].slice(2,varAllDb5[iw+3].length)+"/";
		    		
		    		tempvar=xhbiaji[i][ig];//拿到当前的客户名。
		    	}
		  
		    }
		   
		hbmd=hbmd.slice(0,hbmd.length-1);
		tempvar1=tempvar1.slice(0,tempvar1.length-1);
		$('#wwf').children("table").children("tbody").append("<tr>"             
		+"<th>"+varAllDb6[riqijs].slice(2,varAllDb6[riqijs].length)+"</th>"
		+"<th>"+varAllDb6[riqijs+1].slice(2,varAllDb6[riqijs+1].length)+"</th>"
		+"<th>"+varAllDb4[i*9].slice(2,varAllDb4[i*9].length)+"</th>"
		+"<th>"+varAllDb4[i*9+1].slice(2,varAllDb4[i*9+1].length)+"</th>"
		+"<th>"+tempvar.slice(2,tempvar.length)+"</th>"
		+"<th>"+varAllDb4[i*9+3].slice(2,varAllDb4[i*9+3].length)+"</th>"
		+"<th>"+varAllDb4[i*9+4].slice(2,varAllDb4[i*9+4].length)+"</th>"
		+"<th>"+varAllDb4[i*9+2].slice(2,varAllDb4[i*9+2].length)+varAllDb4[i*9+5].slice(2,varAllDb4[i*9+5].length)+"</th>"
		+"<th>"+hbmd+"</th>"
		+"<th>"+varAllDb4[i*9+6].slice(2,varAllDb4[i*9+6].length)+"</th>"
		+"<th>"+varAllDb4[i*9+7].slice(2,varAllDb4[i*9+7].length)+"</th>"
		+"<th>"+varAllDb4[i*9+8].slice(2,varAllDb4[i*9+8].length)+"</th>"	
		+"<th>"+hbmdjs+"</th>"
		+"<th>"+tempvar1+"</th>"
		+"</tr>");
		var hbmd="";//合并门店
		var hbmdjs=0;
		var tempvar="";//保存客户名称。	
		var tempvar1="";
		
		}
	riqijs=riqijs+2;
}


//console.log(xhbiaji[1]);
//汇总信息
/* var riqijs=0;//管理派车日期 出车日期。
var sj="";
var cp="";
for(var i=0;i<varAllDb4.length;i=i+9)
{
	var hbmd="";//合并门店
	for(var ig=0;ig<varAllDb5.length;ig=ig+4)
		{
		   
		   if(varAllDb4[i].slice(0,2)==varAllDb5[ig].slice(0,2))
			   {
			   
			  
			   hbmd=hbmd+varAllDb5[ig].slice(2,varAllDb5[ig].length)+"/";//保存单表配送门店
			   sj=varAllDb5[ig+1].slice(2,varAllDb5[ig+1].length);//保存司机
			   cp=varAllDb5[ig+2].slice(2,varAllDb5[ig+2].length);//保存车牌 
			 
			   //当前td行的司机车牌与下一td行的司机车牌不一致就写入当前td行，否则新启一行。
			   //js不能处理数组跨界异常，只能手动处理，到最后一行td直接处理数据。php可以处理跨界异常直接返回false，js直接退出。
			   if(ig!=varAllDb5.length-5){
			   if(sj!=varAllDb5[ig+5+1].slice(2,varAllDb5[ig+5+1].length)&&cp!=varAllDb5[ig+5+2].slice(2,varAllDb5[ig+5+2].length))
			   {
				        hbmd=hbmd.slice(0,hbmd.length-1);
			            $('#wwf').children("table").children("tbody").append("<tr>"             
					    +"<th>"+varAllDb6[riqijs].slice(2,varAllDb6[riqijs].length)+"</th>"
					    +"<th>"+varAllDb6[riqijs+1].slice(2,varAllDb6[riqijs+1].length)+"</th>"
					    +"<th>"+varAllDb4[i].slice(2,varAllDb4[i].length)+"</th>"
					    +"<th>"+varAllDb4[i+1].slice(2,varAllDb4[i+1].length)+"</th>"
					    +"<th>"+varAllDb4[i+2].slice(2,varAllDb4[i+2].length)+"</th>"
					    +"<th>"+varAllDb4[i+3].slice(2,varAllDb4[i+3].length)+"</th>"
					    +"<th>"+varAllDb4[i+4].slice(2,varAllDb4[i+4].length)+"</th>"
					    +"<th>"+varAllDb4[i+5].slice(2,varAllDb4[i+5].length)+"</th>"
					    +"<th>"+hbmd+"</th>"
					    +"<th>"+varAllDb5[ig+1].slice(2,varAllDb5[ig+1].length)+"</th>"
					    +"<th>"+varAllDb5[ig+2].slice(2,varAllDb5[ig+2].length)+"</th>"
					    +"<th>"+varAllDb5[ig+3].slice(2,varAllDb5[ig+3].length)+"</th>"	
					    +"<th>"+varAllDb5[ig+4].slice(2,varAllDb5[ig+4].length)+"</th>"
					    +"</tr>");
			            var hbmd="";//合并门店
			   }}else{
				            hbmd=hbmd.slice(0,hbmd.length-1);
				            $('#wwf').children("table").children("tbody").append("<tr>"             
						    +"<th>"+varAllDb6[riqijs].slice(2,varAllDb6[riqijs].length)+"</th>"
						    +"<th>"+varAllDb6[riqijs+1].slice(2,varAllDb6[riqijs+1].length)+"</th>"
						    +"<th>"+varAllDb4[i].slice(2,varAllDb4[i].length)+"</th>"
						    +"<th>"+varAllDb4[i+1].slice(2,varAllDb4[i+1].length)+"</th>"
						    +"<th>"+varAllDb4[i+2].slice(2,varAllDb4[i+2].length)+"</th>"
						    +"<th>"+varAllDb4[i+3].slice(2,varAllDb4[i+3].length)+"</th>"
						    +"<th>"+varAllDb4[i+4].slice(2,varAllDb4[i+4].length)+"</th>"
						    +"<th>"+varAllDb4[i+5].slice(2,varAllDb4[i+5].length)+"</th>"
						    +"<th>"+hbmd+"</th>"
						    +"<th>"+varAllDb5[ig+1].slice(2,varAllDb5[ig+1].length)+"</th>"
						    +"<th>"+varAllDb5[ig+2].slice(2,varAllDb5[ig+2].length)+"</th>"
						    +"<th>"+varAllDb5[ig+3].slice(2,varAllDb5[ig+3].length)+"</th>"	
						    +"<th>"+varAllDb5[ig+4].slice(2,varAllDb5[ig+4].length)+"</th>"
						    +"</tr>");
				            var hbmd="";//合并门店
			   }			  
			   } 
		   				  
		}
	
	
	riqijs=riqijs+2;
}  */
var a01=varAllDb1;//车牌 varAllDb1
var a02=varAllDb2;//司机 varAllDb2
var a03=varAllDb3;//订单表varAllDb3
var a04=varAllDb5;//派车信息 varAllDb5
var a05=varAllDb4;//表头信息varAllDb4

//如果司机 车牌 门店 在派车信息中被找到则删除相应元素。
for(var i=1;i<varAllDb1.length;i=i+2)
{
	for(var ig=0;ig<varAllDb4.length;ig=ig+1){
		if(varAllDb1[i]==varAllDb4[ig].slice(2,varAllDb4[ig].length))
		{	
			//console.log(a01); 
			delete a01[i-1];//找到使用车牌后删除车牌和它的前置备注。
			delete a01[i];		
			
		}
	}	
}
//console.log(a01);
for(var i=0;i<varAllDb2.length;i=i+1)
{
	for(var ig=0;ig<varAllDb4.length;ig=ig+1){
		if(varAllDb2[i]==varAllDb4[ig].slice(2,varAllDb4[ig].length))
		{		
			delete a02[i-1];//找到使用司机后删除司机和它的前置备注。
			delete a02[i];			
		}
	}	
}
for(var i=0;i<varAllDb3.length;i=i+1)
{
	var vtemp1=varAllDb3[i].split('+');
	var ifarr1=vtemp1[0]+vtemp1[1];//合并订单表客户和门店名.
	for(var ig=0;ig<varAllDb5.length;ig=ig+4){		
		//合并派车信息客户和门店名。
		var ifarr2=varAllDb5[ig].slice(2,varAllDb5[ig].length)+varAllDb5[ig+1].slice(2,varAllDb5[ig+1].length);
		if(ifarr1==ifarr2)
		{				
			delete a03[i];			
		}
	}	
}
//去除空值。
var r1 = a01.filter(function (s) {
	   return s && s.trim();
	});
var r2 = a02.filter(function (s) {
	   return s && s.trim();
	});
var r3 = a03.filter(function (s) {
	   return s && s.trim();
	});
$('#a01').text("未使用车辆:"+r1);
$('#a02').text("未使用司机:"+r2);
$('#a03').text("未派车门店:"+r3);
//$('#a04').text(a04);
</script>

</body>

</html>